<template>
	<view>
		<cu-custom bgColor="bg-gradual-gold" title="金华人才卡" :isBack="true" backText="返回"></cu-custom>
		<view class="bg-white" style="padding-top: 20rpx;">
			<view class="box" >
				<view style="padding: 20rpx 0 0 45rpx;"><text class="text-black" style="font-size: 36rpx;">NO.{{talentData.personNo}}</text></view>
				<view style="padding: 80rpx 0 0 0;display: flex;position: relative;align-items: center;justify-content: center;">
					<view v-if="false" style="width: 160rpx;height: 160rpx;">
						<img style="width: 100%;height: 100%;" :src="photoPath">
					</view>
					<view style="padding-left: 50rpx;">
						<view style=""><text class="text-black" style="font-size: 36rpx;letter-spacing:10rpx">持卡人：</text><text class="text-black" style="font-size: 36rpx;letter-spacing:10rpx">{{talentData.fullName}}</text></view>
						<view style=""><text class="text-black" style="font-size: 36rpx;letter-spacing:10rpx">类&emsp;别：</text><text class="text-black" style="font-size: 36rpx;letter-spacing:10rpx">{{talentData.talentTypeName}}</text></view>
					</view>
				</view>
			</view>
			<view class="text-gold text-center" style="padding-top: 20rpx;">
				<text style="font-size: 60rpx;">金华人才码</text>
			</view>
			<view class="text-center" style="font-size: 52rpx;">{{ currentTime }}</view>
			<view class="text-gold text-center">
				<view v-if="codeUrl"><image :src="codeUrl" style="width: 600rpx;height: 600rpx;"></image></view>
			</view>
			<view class="text-gray text-center padding" @click="initCodeUrl">
				<text>{{ codeText }}</text>
				<text class="cuIcon-refresh"></text>
			</view>
		</view>
	</view>
</template>

<script>
	import store from "@/store"
	import reqConfig from '@/common/config/reqConfig.js';
	import api from '@/api/society/my/personTalent.js';
	import miment from 'miment'
	export default {
		data() {
			return {
				timer: '', //定义一个定时器的变量
				reloadTimer: '', //刷新二维码定义一个定时器的变量
				currentTime: miment().format('YYYY年MM月DD日 hh:mm:ss'), // 获取当前时间
				codeClick: true,
				codeText: '扫一扫上面的二维码图案，查看我名片',
				codeUrl: null,
				talentData:{},
				accessToken: store.state.hh_token,
				sex: store.state.hh_user.sex,
				photoPath: store.state.hh_user.photoPath?store.state.hh_user.photoPath:(sex=='2'?'/static/user/avatar_gril.png':'/static/user/avatar_boy.png')
			}
		},
		onReady() {
			this.initCodeUrl();
			this.getTalentData();
		},
		onLoad() {
			var vm = this;
			vm.timer = setInterval(() => {
				vm.currentTime = miment().format('YYYY年MM月DD日 hh:mm:ss')
			}, 1000);
		},
		methods: {
			initCodeUrl() {
				const vm = this;
				if (vm.codeClick) {
					const url =
						reqConfig.baseUrl +
						'/app/api/QRCode/getQRCode?accessToken='+this.accessToken+'&applyType=3&time=' +
						new Date().getTime();
					vm.codeUrl = url;
					vm.codeClick = false;
					vm.codeText = '已刷新';
					// 倒计时开始
					let daojishi = 300;
					vm.reloadTimer = setInterval(function() {
						daojishi--;
						if (daojishi <= 290) {
							vm.codeText = '扫一扫上面的二维码图案，查看我名片';
						}
						if (daojishi <= 0) {
							vm.codeClick = true;
							clearInterval(vm.reloadTimer);
							vm.initCodeUrl();
						}
					}, 1000);
				}
			},
			getTalentData(){
				const data = {};
				this.$http.post(api.getTalentData, data).then(res =>  {
					this.talentData = res.result
				}).catch(err => {
				});
			}
		},
		beforeDestroy() {
			if (this.timer) {
				clearInterval(this.timer); // 在Vue实例销毁前，清除我们的定时器
			}
			if (this.reloadTimer) {
				clearInterval(this.reloadTimer); // 在Vue实例销毁前，清除我们的定时器
			}
		}
	}
</script>

<style lang="scss">
.box{
	width: 700rpx;
	height: 450rpx;
	border-radius: 65rpx;
	margin: 0 auto;
	background-image: url('https://ewm.rsj.jinhua.gov.cn/jhrs/api/common/file/show/jycy/4ab97432ab144283884c7ac28171233c');
	background-size: 100% 100%;
	box-shadow: 0 5rpx 20rpx 0rpx rgba(205, 127, 50, .2); 
}
</style>
